<?php

require_once 'model/file.class.php';

class Core_Table_File extends Database_Table
{
	protected $_name = 'core_file';

	protected $_rowClass = 'Core_Table_Model_File';

	/**
	 * clear temporary file after 1 hours.
	 * @return void
	 */
	function gc()
	{
		/**
		 * select temporary file that does not belong to any id.
		 * @return void
		 */
		$select = $this -> select() -> where('resource_id=0') -> where('created_at<?', time() - 3600) -> limit(100);

		$files = $this -> fetchAll($select);

		foreach ($files as $file)
		{
			try
			{
				$file -> delete();
			}
			catch(Exception $e)
			{
				//skip error
			}
		}
	}
}